import { createStore } from "redux";
export type reduxType = "set_room"
export type dispatchType = {
    type: reduxType,
    data: any
}
const initialState = {
    room: null
}
export type initialStateType = typeof initialState
const reducer = (
    state: initialStateType,
    { type, data }: { type: reduxType, data: any }
) => {
    switch (type) {
        case "set_room":
            return { ...state, room: data }
            break;
        default:
            return initialState;
    }
}
let store: any;
/**
 * 服务端保存store传到客户端，通过_app将服务端传来的store再保存至客户端。
 * 使服务端和客户端数据保持同步
 */
const initializeStore = (preloadedState = initialState) => {
    const _store = store ?? createStore(reducer)
    if (typeof window === "undefined") return _store;
    if (!store) store = _store;
    return _store;
}
export default initializeStore